package vn.com.epi.re.table;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

public class ArticleTable {

    public ArticleTable() {        
    }
    
    public static final String NAME = "Article";
    public static final  byte[] NAME_BYTES = Bytes.toBytes("Article");
    public static final byte[] FAM_MAIN = Bytes.toBytes("main");
    public static final byte[] COL_FIRST_VISIT_TIMESTAMPS = Bytes.toBytes("firstVisitTimestamps");
    public static final byte[] COL_CATEGORY_ID = Bytes.toBytes("categoryId");
    public static final byte[] COL_TOTAL_COUNT = Bytes.toBytes("totalCount");    

    public static int getCategoryId(Result result) {
        int categoryId;
        try {
            categoryId = Bytes.toInt(result.getValue(FAM_MAIN, COL_CATEGORY_ID)); 
        } catch (Exception e) {
            categoryId = 0;
        }
        return categoryId;
    }
    
    public static int getTotalCount(Result result) {
        int totalCount;
        try {
            totalCount = Bytes.toInt(result.getValue(FAM_MAIN, COL_TOTAL_COUNT)); 
        } catch (Exception e) {
            totalCount = 0;
        }
        return totalCount;
    }
    
    public static long getFirstVisitTimestamp(Result result) {
        long timestamp;
        try {
            timestamp = Bytes.toLong(result.getValue(FAM_MAIN, COL_FIRST_VISIT_TIMESTAMPS));
        } catch (Exception e) {
            timestamp = 0;
        }
        return timestamp;
    }
    
}
